-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[entt] Tool check_min_cppstd already validates default 'cppstd' values #3840
Conversation
Some configurations of 'entt/3.2.2' failed in build 1 (
|
It does not check C++ standard support of compilers (which can be complex, because a partial support of C++ standard for some library might be sufficient, while not for another library using others features). |
yes, that might be harder than it initially appears. many compilers declare support for particular standards, but either does not fully support them or have some bugs in the implementation. it would be too much for conan to validate the support (as it will require thousands of test cases). |
For this particular recipe (in fact in all recipes with this pattern), Visual Studio min version should be set to 15 instead of 15.9, since |
The underlying issue is c3i itself, we are not iterating any profile with C++17 enabled and we need to write these workarounds in the recipes. After adding the new configurations for new |
Using VisualStudio 15 should be enough to "fix" the issue reported here: skypjack/entt#606 |
Here is a simple function which could allow to check compiler version against a min version: def compare_compiler_version(version1, version2):
v1, *v1_res = version1.split(".", 1)
v2, *v2_res = version2.split(".", 1)
if v1 == v2 and v1_res and v2_res:
return compare_compiler_version(v1_res[0], v2_res[0])
return v1 >= v2
checks = [
["15", "14"],
["15", "15"],
["15", "16"],
["15", "15.1"],
["14", "15.1"],
["16", "15.1"],
["16", "15.8.9"],
["14.1.5", "15.1"],
["15.1.7", "15.1"],
["15.1.7", "15.1.8"],
["15.1.9", "15.1.8"]
]
for check in checks:
print("version {0} >= version {1}: {2}".format(check[0], check[1], compare_compiler_version(check[0], check[1]))) output:
This way, we can keep the detailed information about min compiler version, while allowing to have a less accurate version in profile. |
All green in build 2 (
|
@SpaceIm , I see the intention, but having a look at Conan sources I'm afraid using Nevertheless, Conan behavior doesn't justify a wrong implementation here. I can add your smart version-checker to the recipe. |
Yes my intention was to add this function for these specific checks in the recipe, not in conan library itself. This issue is not specific to Visual Studio. Loot at #3320, cpp-sort asks for gcc 5.5 as a minimum in |
Let's see if we can allocate some time and prioritize the profiles using other C++ standards, I think it is totally needed and now we are at the point where we can start to implement these things more easily. But more profiles are more resources, more time and more chances to fail unexpectedly... more fun! 😅 |
An unexpected error happened and has been reported. Help is on its way! 🏇 |
All green in build 4 (
|
recipes/entt/3.x.x/conanfile.py
Outdated
if version < minimal_version[compiler]: | ||
# Compare versions asuming minor satisfies if not explicitly set | ||
def gte_compiler_version(version1, version2): | ||
v1, *v1_res = version1.split(".", 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this implementation as it may lead into infinite loops. there is a Version
class for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of input could lead to infinite loop (empty string maybe)? Can Version handle the logic implemented in this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Version
class will consider minor
equals to 0
if it is not set, which is exactly the opposite of what we are doing here. The expression tools.Version(version1) >= tools.Version(version2)
doesn't work the same.
About infinite recursion... it would require infinite .
in both versions
recipes/entt/3.x.x/conanfile.py
Outdated
# FIXME: Here we are implementing a workaround because ConanCenter is not generating any configuration with | ||
# C++17 support (either supported by default by a compiler or using 'compiler.cppstd=17' in the Conan profile) | ||
# and ConanCenter requires that at least one package is generated. Once ConanCenter uses a profile | ||
# with C++17 support, only a raw call to `tools.check_mis_cppstd(self, "17")` will be required. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this comment by the way? All CCI recipes requiring at least C++14 have this kind of pattern.
Do you mean that in future conan version, a profile without compiler.cppstd=17
(or higher) won't be able to consume or build a library requiring at least C++17, so we won't be able to mix different standard in the dependency graph?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The C++ standard should be known by Conan in order to select the proper binary. Once we start to generate here binaries for stable C++ standards, recipes might look like the following:
- A recipe that needs C++17 to build, but the API is C++11 compatible:
class Recipe:
def validate(self):
tools.check_min_cppstd(self, "17") # This is needed to build
def package_id(self):
# If the API is compatible for >=C++11, we can fallback to any binary available
for cppstd in ("11", "14", "17", "20"):
compatible_pkg = self.info.clone()
compatible_pkg.settings.compiler.cppstd = cppstd
self.compatible_packages.append(compatible_pkg)
So, a profile without compiler.cppstd
will be suitable to consume this library if the default for the compiler is at least C++11, but only a profile with explicit compiler.cppstd=17
or compiler.cppstd=20
will be able to generate this library.
Behind the scenes, Conan keeps the exception raises by the check_min_cppstd
and only raise it if the command is trying to build the library, otherwise this package remains in the graph with package_id = INVALID
(that would be the output for conan info
command), and it will fall back to the compatible package if we need a binary to install.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this implementation, you can mix binaries from different C++ standards because they are declared compatible not just because a hidden CXX_STANDARD 17
in the CMakeLists.txt
was able to generate the binary. I think it is preferred to make it explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if default standard of a compiler version is lower than the minimum standard required by the library, but still supports enough features of this standard for this library? Will it work if standard is not explicitly set in profile?
Moreover, AFAIK tools.check_min_cppstd(self, "17")
raises if standard is not set in profile, so it requires modifications in this function.
What happen if a consumer tries to build from source with an unsupported compiler? Currently, it gracefully fails, while with this implementation it will fail at some point during build()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if default standard of a compiler version is lower than the minimum standard required by the library, but still supports enough features of this standard for this library? Will it work if standard is not explicitly set in profile?
We cannot handle this situation, if the recipe says tools.check_min_cppstd(self, "17")
it will fail if the compiler doesn`t implement that standard (if it is declared stable). If it only needs some features that are available in previous versions, the recipe will need some handcrafted checks... but I would try to avoid them as much as possible (in my 🦄 world).
Moreover, AFAIK
tools.check_min_cppstd(self, "17")
raises if standard is not set in profile, so it requires modifications in this function.
No, it doesn't (https://github.com/conan-io/conan/blob/develop/conans/client/tools/settings.py#L5). You saying that is a symptom of the workaround we are using in the recipe to bypass the fact that ConanCenter is not trying any profile with C++14/17/20 support.
What happen if a consumer tries to build from source with an unsupported compiler? Currently, it gracefully fails, while with this implementation it will fail at some point during build()
It will fail gracefully, have a look at the docs about validate()
function: https://docs.conan.io/en/latest/reference/conanfile/methods.html?highlight=validate#validate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, but if compiler.cppstd
is not set in profile, tools.check_min_cppstd
raises if default standard -as estimated by conan- is not sufficient.
https://github.com/conan-io/conan/blob/61d75d945a0e16a56a320926789cff2d297ac76a/conans/client/tools/settings.py#L50
https://github.com/conan-io/conan/blob/61d75d945a0e16a56a320926789cff2d297ac76a/conans/client/build/cppstd_flags.py#L50
Currently, tools.check_min_cppstd(self, 17)
raises with all versions of Visual Studio -even Visual Studio 2019- if compiler.cppstd
is not set.
https://github.com/conan-io/conan/blob/61d75d945a0e16a56a320926789cff2d297ac76a/conans/client/build/cppstd_flags.py#L78
I believe that, if your first answer in the previous message was implemented as is in CCI recipes, it would break a lot of them (a lot of C++11 recipes work with gcc 4.9/5, while C++11 is not the default standard of those versions).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If compiler.cppstd
is not set in the profile it will fail to build, yes. And it is right because the recipe says C++17 is required and those compilers don't enable C++17 support by default. Activating the standard in the CMakeLists.txt
file is something to avoid, it is hiding changes in the ABI from the package manager.
But, by adding the compatible_packages
feature, Conan will be able to retrieve a compatible binary that was compiled with an explicit compiler.cppstd
value when using a profile without it.
I believe that, if your first answer in the previous message was implemented as is in CCI recipes, it would break a lot of them (a lot of C++11 recipes work with gcc 4.9/5, while C++11 is not the default standard of those versions).
As they are now, those recipes are wrong (because of c3i profiles), they are activating C++11 inside the CMakeLists.txt
, and some of the header-only ones are activating it inside the test_package/CMakeLists.txt
(if you add them to your graph, Conan retrieves a package and then your consumer fails to compile without further notice). If you modify those recipes as the draft in the first commit they will fail to build if you do not provide a compatible configuration in the profile (nothing hidden) but you still can consume them with a lower C++ standard if the API is compatible and the binary is available (it was compiled with a higher C++ standard).
Maybe this requires a written example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If compiler.cppstd is not set in the profile it will fail to build, yes. And it is right because the recipe says C++17 is required and those compilers don't enable C++17 support by default. Activating the standard in the CMakeLists.txt file is something to avoid, it is hiding changes in the ABI from the package manager.
I strongly disagree.
It's not wrong to activate C++11/14/17 in CMakeLists.txt, it's what all C++11/14/17 libraries in the world do. I don't understand your point. It fails in test_package if C++ standard is not set, because conan doesn't provide a way (or if it does, nobody use it in CCI recipes) to easily propage this information in generators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've written an example with a (opinionated) dramatization here: conan-io/examples#73. I know every library activates the C++ standard in the CMakeLists.txt
but IMHO it is not the best place to do it. We can move this conversation there (or to another repository) with an example, it is easier for me to show what I want to show.
I will remove the comment in this recipe as this is something we cannot fix right now, but I really think user experience and ConanCenter would benefit from that approach. Please have a look at the recipes in that PR. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks, I'll take a look ;)
Co-authored-by: SpaceIm <[email protected]>
All green in build 5 (
|
All green in build 6 (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good enough for this situation.
👍 thank you all for your hard work on this. Since I still am experiencing:
and/or:
I deduce that either:
Please advise if it's 1, 2 or... something else :) |
@malachib Take a look on this answer: https://stackoverflow.com/questions/64694269/getting-uwebsockets-for-visual-2017-via-conan It looks pretty similar. If it doesn't work, please open an issue. |
Hi, @malachib You are facing a problem not related to this recipe. Conan has a file listing all the settings and their values, have a look at your cache folder ( You can modify them to fit the needs of your company, you can add So, use a profile like this one (notice
|
The magic for me appears to be your suggested Subsequent unadorned I now have EnTT running on VS2017! I also never knew |
Specify library name and version: entt/all
conan-center hook activated.